require.config({
    baseUrl:"../",
    paths:{
        jq: "../libs/jquery.2.2.4",
        getJson: "../public/getJson",
        render: "../modules-list/render",
        setLocal: "../modules-list/setLocal"
    }
})

require(["jq","getJson","render","setLocal"],function(_, gj, r, sl){
    // console.log($)
    // console.log(gj)
    let goods = []
    gj({
        url:"../data/cart.json"
    }).then((res)=>{
        // console.log(res)
        // console.log(r)
        goods = JSON.parse(res)
        r({
            data:goods,
            cont:$(".cate_prod"),
            page:1
        })
        wang()
    }) 
    // console.log(sl)
    $(".cate_prod").on("click",".pbuy",function(){
        // console.log($(this).parent().parent().parent().attr("index"))
        let id=$(this).parent().parent().parent().attr("index");
        let price =$(this).parent().parent()[0].lastElementChild.innerHTML-0;
        sl({id,price,num:1,flag:0})
     
    })

    document.querySelector(".flipr").onclick=function(){
        
        var flipn=this.parentElement.children[0].innerHTML;
        if(flipn>3)return
        this.parentElement.children[0].innerHTML = Number(flipn)+1;
        // console.log(goods)
        r({
            data:goods,
            cont:$(".cate_prod"),
            page:Number(flipn)+1
        })

    }

    document.querySelector(".flipl").onclick=function(){
        
        var flipn=this.parentElement.children[0].innerHTML;
        if(flipn<2)return
        this.parentElement.children[0].innerHTML = Number(flipn)-1;
        r({
            data:goods,
            cont:$(".cate_prod"),
            page:Number(flipn)-1
        })
    }

})
function wang(){
    var p_brandEn = document.querySelectorAll(".p_brandEn")
    for(var i=0;i<p_brandEn.length;i++){
        p_brandEn[i].onclick= function(eve){
            
            location.href=`../details/details.html#`+eve.path[2].getAttribute("index")
        }
    }
}